<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
       * {
        margin: 0;
        padding: 0;
        }
        .ad{
            position: relative;
            margin: 100px auto;
            width: 400px;
            height: 600px;
            background-color: url('') no-repeat center/100% 100%;
        }
        .ad .close{
            position: absolute;
            top: 5px;
            right: 5px;
            width: 30px;
            height: 50px;
            border: 1px solid red;
            font-size: 32px;

        
        }
    </style>
</head>
<body>
    <div class="ad">1</div>
    <div class="ad">2</div>
    <div class="ad">3</div>

  <div class="ad">3
    <!-- 这是注释语句-->
    <h3 class="close">X</h3>
    <h3 class="close2">X</h3>
    <h3 class="close3">X</h3>
  </div>
</body>
<script>
    const clo = document.querySelector('.close');  //获取close关闭元素节点
    const ad = document.querySelectorAll('.ad');  //获取类名ad的元素节点
    //给关闭按钮添加监听事件
    clo.addEventListener('click',function(){
        //事件处理程序
        clo.parentElement.style.display = 'none';
       // ad[2].style.display = 'none';
        const ad = document.querySelector('.ad');  //获取类名ad的元素节点
        ad.style.display = 'none';
    },false);
    console.log(clo.parentNode);
    console.log(clo.parentElement);
    console.log('------');
    console.log(ad[2].childNodes);
    console.log(ad[2].children);
    console.log('------');
    console.log(clo.previousElementSibling);
    console.log(ad[2].nextElementSibling);
</script>
</html>